<script>
    //工具栏绑定事件
    function builderToolbarEvent(resData,soulTable,myTable,table,layer){
        table.on('toolbar(myTable)', function (obj) {
            // console.log(obj, table.checkStatus(obj.config.id));
            var checkStatus = table.checkStatus(obj.config.id);
            var ids = '';
            if (checkStatus.data.length > 0) {
                for (var i = 0; i < checkStatus.data.length; i++) {
                    ids += checkStatus.data[i]['id'] + ",";
                }
                ids = ids.substr(0, ids.length - 1);
            }
            switch (obj.event) {
                //删除勾选数据
                case 'deletes':
                    if (ids != '') {
                     
                         layer.confirm('ID组：'+ids, {
                            title:'是否删除以下数据？',
                            area:['300px','auto'],
                            btn: ['确定', '取消'], //可以无限个按钮
                            skin: '', //样式类名
                        }, function (index, layero) {
                            //删除所有的ids
                            var http = new Request({token_url:api.token_url,async:false,token_store_name:'delete'});
                            var res = http.request('post',resData.top_delete_url,{ids:ids});
                            if(res.code == 0){
                                
                                layer.msg('删除成功');
                                myTable.reload();
                            }else{
                                layer.msg('删除失败！',function(){});
                            }

                        }, function (index) {
                            //按钮【按钮二】的回调
                            layer.closeAll();
                        });


                    } else {
                        layer.msg('请勾选需要删除的数据！', function () { });
                    }
                    break;
                //新增|添加
                case 'add':
                    //二维码显示
                    if (resData.top_add_show_qrcode) {
                        var html = '<style>#top_add_qrcode{align-items: center;display:flex;justify-content:center;height:100%;}#top_add_qrcode img{width:160px;height:160px;}<\/style><div id="top_add_qrcode"></div><script>new QRCode("top_add_qrcode", { text:"' + resData["top_add_url"] + '",width: "160",height: "160",colorDark: "#000000",colorLight: "#ffffff",correctLevel: QRCode.CorrectLevel.H});<\/script>';
                        layer.open({
                            type: 1,
                            title: '请扫一扫二维码',
                            area: ['250px', '250px'], //宽高
                            skin: 'layui-layer-demo', //样式类名
                            closeBtn: 1, //不显示关闭按钮
                            anim: 2,
                            shadeClose: true, //开启遮罩关闭
                            content: html
                        });

                    } else {
                        // console.log(resData['top_add_url'],resData['is_hash_add'],resData['top_add_url'].indexOf('#'));
                        // return ;
                        if(resData['is_hash_add']){
                            //顶部添加事件，删除?后面的参数
                            if(resData['top_add_url'].indexOf('#')>=0){
                                window.location.href = (resData['base_url'] + resData['top_add_url']);
                            }else{
                                window.location.href = (resData['base_url'] + "#" + resData['top_add_url']);
                            }
                           
                        }else{
                            window.location.href = resData['top_add_url'];
                        }
                       console.log(resData['top_add_url'],resData['is_hash_add'],resData['top_add_url'].indexOf('#'));
                        //跳转到添加页面 通过修改hash实现跳转
                        // location.hash = resData['top_add_url'];
                        
                    }
                    break;
                //导出选中数据
                case 'exportCheckedExcel':
                    if (ids != '') {
                        if (resData['export_excel_url'] == '') {
                            soulTable.export(myTable, {
                                filename: resData.excel_name,
                                checked: true // 只导出勾选数据
                            });
                        } else {
                            if (window.location.search == '') {
                                window.open(resData['export_excel_url'] + "?ids=" + ids, "_self");
                            } else {
                                window.open(resData['export_excel_url'] + window.location.search + "&ids=" + ids, "_self");
                            }
                        }

                    } else {
                        layer.msg('请勾选需要导出的数据！',function(){});
                    }
                    break;
                //导出全部  
                case 'exportExcel':
                    if (resData['export_excel_url'] == '') {
                        var http = new Request({token_url:api.token_url,async:false,token_store_name:'export'}), res = { code: 1, data: { 'data': [] } };
                        if (window.location.search != '') {
                            res = http.request('get', resData.table_data_url + window.location.search + "&page=1&pageSize=1000000");
                        } else {
                            res = http.request('get', resData.table_data_url + "?page=1&pageSize=1000000")
                        }
                        var config = {
                            checked: false, // 导出当前勾选数据数据
                            data: res.data.data, // 指定数据导出
                            filename: resData.excel_name, // 文件名
                            head: { // 表头样式
                                family: 'Calibri', // 字体
                                size: 12, // 字号
                                color: '000000', // 字体颜色
                                bgColor: 'FFFFFF' // 背景颜色
                            },
                            font: { // 正文样式
                                family: 'Calibri', // 字体
                                size: 12, // 字号
                                color: '111111', // 字体颜色
                                bgColor: 'FFFFFF' //背景颜色
                            }
                        };
                        soulTable.export(myTable, config);
                    } else {
                        window.open(resData['export_excel_url'] + window.location.search, "_self");
                    }
                    break;
                default:
                    break;    
            }


        });
    }
</script>